package internal

const (
	CacheKeySQLTableOperateCacheSuffix = "sqlTableOperateCache"
	CacheKeyURLEntityCacheSuffix       = "urlEntityCache"

	MessageBroker = "MessageBroker"
	ExternalName  = "External"

	DatastoreStatement = "Datastore/statement"
	DatastoreOperation = "Datastore/operation"
	DatabaseStatement  = "Database/statement"

	DefaultPort = ""
	DefaultHost = ""
	DefaultDb   = ""

	DataStore    = 1
	External     = 2
	Database     = 3
	Message      = 4
	CommonMetric = 5

	// transaction info spans 下的kind
	DataStoreRedis        = 1
	DataStoreMongodb      = 2
	DataStoreMemcached    = 3
	DataStorexMemcached   = 4
	DataStorespyMemcached = 5

	DataStoreCassandra = 6
	DataStoreInfluxDB  = 27

	CqlSelectPatternCassandra = "(?i)^\\s*SELECT\\s+(.*)\\s+FROM\\s+([\\.\\w]+)"
	CqlInsertPatternCassandra = "(?i)^\\s*INSERT\\s+INTO\\s+([\\.\\w]+)"
	CqlDeletePatternCassandra = "(?i)^\\s*DELETE(\\s+(.*)\\s+|\\s+)FROM\\s+([\\.\\w]+)"
	CqlUpdatePatternCassandra = "(?i)^\\s*UPDATE\\s+([\\.\\w]+)"

	CqlSelectPatternInfluxdb = "(?i)^\\s*SELECT\\s+(.*)\\s+FROM\\s+([\\.\\w]+)"
	CqlInsertPatternInfluxdb = "(?i)^\\s*INSERT\\s+([\\.\\w]+),\\s*"
	CqlDeletePatternInfluxdb = "(?i)^\\s*DELETE(\\s+(.*)\\s+|\\s+)FROM\\s+([\\.\\w]+)"

	DatabaseMysql      = "mysql"
	DatabaseMysqlPort  = "3306"
	DatabaseMariadb    = "mariadb"
	DatabaseOracle     = "oracle"
	DatabaseSQLServer  = "mssql"
	DatabaseSybase     = "sybase"
	DatabaseJtds       = "jtds"
	DatabaseJtdsPort   = 1433
	DatabasePostgreSQL = "postgresql"
	DatabaseHsql       = "hsqldb"
	DatabaseDB2        = "db2"
	DatabaseDB2Port    = "50000"
	DatabaseSqlite     = "sqlite"
	DatabaseH2         = "h2"
	DatabaseCloudScape = "cloudscape"
	DatabaseInformix   = "informix"
	DatabaseDm         = "dm"
	DatabaseOscar      = "oscar"
)

var CommonMetricKindInfo = []string{"Servlet", "Jsp", "Java", "Hibernate", "SpringController", "StrutsAction", "Dorado", "ESB",
	"TapestryEngineService", "TapestryView", "OtherTransaction/Job/emoryConcurrentCallable",
	"StrutsResult", "OtherTransaction/Job", "Tuxedo", "Portlet", "ExternalHessian", "ExternalBurlap",
	"Filter", "http"}

var MongodbOpArray = []string{"", "insert", "update", "remove", "createIndex", "find", "save", "drop", "find_one", "count", "create_index", "ensure_index", "drop_indexes", "drop_index", "reindex", "index_information", "options", "group", "rename", "distinct", "map_reduce", "inline_map_reduce", "find_and_modify", "insert_one"}

var RedisOpArr = []string{
	"", "set", "get", "append", "getset", "del", "mset", "exists", "mget", "smembers", "sadd", "brpop", "hset", "expire", "hexists", "hmget", "hget", "hmset", "bgrewriteaof", "bgsave", "client_kill", "client_list", "client_getname", "client_setname", "config_get", "config_set", "config_resetstat", "config_rewrite", "dbsize", "debug_object", "echo", "flushall", "flushdb", "info", "lastsave", "object", "ping", "save", "sentinel", "sentinel_get_master_addr_by_name", "sentinel_master", "sentinel_masters", "sentinel_monitor", "sentinel_remove", "sentinel_sentinels", "sentinel_set", "sentinel_slaves", "shutdown", "slaveof", "slowlog_get", "slowlog_reset", "time", "bitcount", "bitop", "bitpos", "decr", "delete", "dump", "expireat", "getbit", "getrange", "incr", "incrby", "incrbyfloat", "keys", "mset", "msetnx", "move", "persist", "pexpire", "pexpireat", "psetex", "pttl", "randomkey", "rename", "renamenx", "restore", "setbit", "setex", "setnx", "setrange", "strlen", "substr", "ttl", "type", "watch", "unwatch", "blpop", "brpoplpush", "lindex", "linsert", "llen", "lpop", "lpush", "lpushx", "lrange", "lrem", "lset", "ltrim", "rpop", "rpoplpush", "rpush", "rpushx", "sort", "scan", "scan_iter", "sscan", "sscan_iter", "hscan", "hscan_inter", "zscan", "zscan_iter", "scard", "sdiff", "sdiffstore", "sinter", "sinterstore", "sismember", "smove", "spop", "srandmember", "srem", "sunion", "sunionstore", "zadd", "zcard", "zcount", "zincrby", "zinterstore", "zlexcount", "zrange", "zrangebylex", "zrangebyscore", "zrank", "zrem", "zremrangebylex", "zremrangebyrank", "zremrangebyscore", "zrevrange", "zrevrangebyscore", "zrevrank", "zscore", "zunionstore", "pfadd", "pfcount", "pfmerge", "hdel", "hgetall", "hincrby", "hincrbyfloat", "hkeys", "hlen", "hsetnx", "hvals", "publish", "eval", "evalsha", "script_exists", "script_flush", "script_kill", "script_load",
}

var Memcached = []string{"delete", "set", "add", "append", "get", "gets", "getmultiarray", "replace", "addorincr", "addordecr", "increment", "decrement", "prepend", "touch", "set_many", "cas", "get_many", "gets_many", "delete_many", "incr", "decr", "stats", "flush_all", "quit"}

// KindInfo 注意：这里定义两份，而没有定义一份然后大小写自动转换，是因为有一些对应的other_sql，还有memcached对应oneapm三个
var KindInfo = map[int32]map[string]string{
	1: {
		"oneapm": "Redis",
		"ot":     "redis",
	},
	2: {
		"oneapm": "MongoDB",
		"ot":     "mongodb",
	},
	3: {
		"oneapm": "Memcached",
		"ot":     "memcached",
	},
	4: {
		"oneapm": "xMemcached",
		"ot":     "memcached",
	},
	5: {
		"oneapm": "spymemcached",
		"ot":     "memcached",
	},
	6: {
		"oneapm": "Cassandra",
		"ot":     "cassandra",
	},
	7: {
		"oneapm": "HTTP",
		"ot":     "http",
	},
	8: {
		"oneapm": "xmlRpc",
		"ot":     "xmlRpc",
	},
	10: {
		"oneapm": "ejb",
		"ot":     "ejb",
	},
	11: {
		"oneapm": "Dubbo",
		"ot":     "Dubbo",
	},
	12: {
		"oneapm": "SpringRMI",
		"ot":     "SpringRMI",
	},
	13: {
		"oneapm": "HSF",
		"ot":     "HSF",
	},
	14: {
		"oneapm": "Thrift",
		"ot":     "Thrift",
	},
	15: {
		"oneapm": "RocketMQ",
		"ot":     "rocketmq",
	},
	16: {
		"oneapm": "RabbitMQ",
		"ot":     "rabbitmq",
	},
	17: {
		"oneapm": "ActiveMQ",
		"ot":     "activemq",
	},
	18: {
		"oneapm": "WebSphereMQ",
		"ot":     "WebSphereMQ",
	},
	19: {
		"oneapm": "TongLQ",
		"ot":     "TongLQ",
	},
	20: {
		"oneapm": "JMS",
		"ot":     "JMS",
	},
	22: {
		"oneapm": "PHPRPC",
		"ot":     "PHPRPC",
	},
	23: {
		"oneapm": "GRPC",
		"ot":     "grpc",
	},
	24: {
		"oneapm": "SWIFTSERVICE",
		"ot":     "SWIFTSERVICE",
	},
	26: {
		"oneapm": "Kafka",
		"ot":     "kafka",
	},
	27: {
		"oneapm": "InfluxDB",
		"ot":     "other_sql",
	},
	28: {
		"oneapm": "Pulsar",
		"ot":     "Pulsar",
	},
	29: {
		"oneapm": "JavaRmi",
		"ot":     "java_rmi",
	},
	30: {
		"oneapm": "Wcf",
		"ot":     "wcf",
	},
	31: {
		"oneapm": "Elasticsearch",
		"ot":     "Elasticsearch",
	},
	32: {
		"oneapm": "Hbase",
		"ot":     "Hbase",
	},
	33: {
		"oneapm": "Hive",
		"ot":     "Hive",
	},
	34: {
		"oneapm": "Redshift",
		"ot":     "Redshift",
	},
	35: {
		"oneapm": "HyperSQL",
		"ot":     "HyperSQL",
	},
	36: {
		"oneapm": "Progress",
		"ot":     "Progress",
	},
	37: {
		"oneapm": "MaxDB",
		"ot":     "MaxDB",
	},
	38: {
		"oneapm": "HanaDB",
		"ot":     "HanaDB",
	},
	39: {
		"oneapm": "Ingress",
		"ot":     "Ingress",
	},
	40: {
		"oneapm": "FirstSql",
		"ot":     "FirstSql",
	},
	41: {
		"oneapm": "Edb",
		"ot":     "Edb",
	},
	42: {
		"oneapm": "Cache",
		"ot":     "Cache",
	},
	43: {
		"oneapm": "Adabas",
		"ot":     "Adabas",
	},
	44: {
		"oneapm": "Firebird",
		"ot":     "Firebird",
	},
	45: {
		"oneapm": "Derby",
		"ot":     "Derby",
	},
	46: {
		"oneapm": "Filemaker",
		"ot":     "Filemaker",
	},
	47: {
		"oneapm": "Instantdb",
		"ot":     "Instantdb",
	},
	48: {
		"oneapm": "Netezza",
		"ot":     "Netezza",
	},
	49: {
		"oneapm": "Pervasive",
		"ot":     "Pervasive",
	},
	50: {
		"oneapm": "Pointbase",
		"ot":     "Pointbase",
	},
	51: {
		"oneapm": "Teradata",
		"ot":     "Teradata",
	},
	52: {
		"oneapm": "Vertica",
		"ot":     "Vertica",
	},
	53: {
		"oneapm": "Coldfusion",
		"ot":     "Coldfusion",
	},
	54: {
		"oneapm": "Couchbase",
		"ot":     "Couchbase",
	},
	55: {
		"oneapm": "Couchdb",
		"ot":     "Couchdb",
	},
	56: {
		"oneapm": "Cosmosdb",
		"ot":     "Cosmosdb",
	},
	57: {
		"oneapm": "Dynamodb",
		"ot":     "Dynamodb",
	},
	58: {
		"oneapm": "Neo4j",
		"ot":     "Neo4j",
	},
	59: {
		"oneapm": "Geode",
		"ot":     "Geode",
	},
	60: {
		"oneapm": "Cockroachdb",
		"ot":     "Cockroachdb",
	},
	113: {
		"oneapm": "mysql",
		"ot":     "mysql",
	},
	114: {
		"oneapm": "mariadb",
		"ot":     "mariadb",
	},
	115: {
		"oneapm": "oracle",
		"ot":     "oracle",
	},
	116: {
		"oneapm": "mssql",
		"ot":     "mssql",
	},
	117: {
		"oneapm": "sybase",
		"ot":     "sybase",
	},
	118: {
		"oneapm": "jtds",
		"ot":     "other_sql",
	},
	119: {
		"oneapm": "postgresql",
		"ot":     "postgresql",
	},
	120: {
		"oneapm": "hsqldb",
		"ot":     "hsqldb",
	},
	121: {
		"oneapm": "db2",
		"ot":     "db2",
	},
	122: {
		"oneapm": "sqlite",
		"ot":     "sqlite",
	},
	123: {
		"oneapm": "h2",
		"ot":     "h2",
	},
	124: {
		"oneapm": "cloudscape",
		"ot":     "cloudscape",
	},
	125: {
		"oneapm": "informix",
		"ot":     "informix",
	},
	126: {
		"oneapm": "dm",
		"ot":     "other_sql",
	},
	127: {
		"oneapm": "oscar",
		"ot":     "other_sql",
	},
}

var MQTypeInfo = map[int32]string{
	1: "Queue",
	2: "Topic",
	3: "TempQueue",
	4: "TempTopic",
}
var MQDestType = map[int32]string{
	1: "Consume",
	2: "Produce",
	3: "Peek",
	4: "Purge",
}

var MethodIndexName = map[int32]string{
	1:   "",
	2:   "__find",
	3:   "__parseHeader",
	4:   "_jspService",
	5:   "absolute",
	6:   "add",
	7:   "addBatch",
	8:   "addOperation",
	9:   "addOperations",
	10:  "addOrDecr",
	11:  "addOrIncr",
	12:  "afterLast",
	13:  "append",
	14:  "basicGet",
	15:  "basicPublish",
	16:  "beforeFirst",
	17:  "blockingUnaryCall",
	18:  "build",
	19:  "call",
	20:  "callBlockingMethod",
	21:  "callMethod",
	22:  "cancelRowUpdates",
	23:  "clearWarnings",
	24:  "cliSendCommand",
	25:  "connect",
	26:  "contextDestroyed",
	27:  "contextInitialized",
	28:  "createIndex",
	29:  "decr",
	30:  "delete",
	31:  "deleteRow",
	32:  "dispatch",
	33:  "doBuildTemplate",
	34:  "doExecute",
	35:  "doInvoke",
	36:  "doOutboundRequest",
	37:  "doService",
	38:  "error",
	39:  "execute",
	40:  "executeAction",
	41:  "executeBulkWriteOperation",
	42:  "executeEvents",
	43:  "executeQuery",
	44:  "executeUpdate",
	45:  "executeWriteOperation",
	46:  "fatal",
	47:  "find",
	48:  "findColumn",
	49:  "first",
	50:  "flush",
	51:  "futureInvoke",
	52:  "get",
	53:  "getArray",
	54:  "getAsciiStream",
	55:  "getBigDecimal",
	56:  "getBinaryStream",
	57:  "getBlob",
	58:  "getBoolean",
	59:  "getByte",
	60:  "getBytes",
	61:  "getCharacterStream",
	62:  "getClob",
	63:  "getConnection",
	64:  "getCursorName",
	65:  "getDB",
	66:  "getDate",
	67:  "getDouble",
	68:  "getFetchDirection",
	69:  "getFetchSize",
	70:  "getFloat",
	71:  "getHoldability",
	72:  "getInt",
	73:  "getLong",
	74:  "getMessage",
	75:  "getMulti",
	76:  "getMultiArray",
	77:  "getNCharacterStream",
	78:  "getNClob",
	79:  "getNString",
	80:  "getObject",
	81:  "getRef",
	82:  "getResponseBody",
	83:  "getRow",
	84:  "getRowId",
	85:  "getSQLXML",
	86:  "getShort",
	87:  "getStatement",
	88:  "getString",
	89:  "getTime",
	90:  "getTimestamp",
	91:  "getType",
	92:  "getURL",
	93:  "getUnicodeStream",
	94:  "getWarnings",
	95:  "gets",
	96:  "handle",
	97:  "handleDelivery",
	98:  "handleFault",
	99:  "handleMessage",
	100: "handleRequest",
	101: "handleURI",
	102: "incr",
	103: "incrWithTTL",
	104: "insert",
	105: "insertImpl",
	106: "insertOperation",
	107: "insertRow",
	108: "invoke",
	109: "invokeWithCallBack",
	110: "isAfterLast",
	111: "isBeforeFirst",
	112: "isClosed",
	113: "isFirst",
	114: "isLast",
	115: "last",
	116: "list",
	117: "load",
	118: "moveToCurrentRow",
	119: "moveToInsertRow",
	120: "next",
	121: "nextDelivery",
	122: "onComplete",
	123: "onMessage",
	124: "parse",
	125: "persist",
	126: "prepend",
	127: "previous",
	128: "process",
	129: "processRequest",
	130: "putMessage",
	131: "receive",
	132: "receiveBase",
	133: "receiveMessage",
	134: "receiveNoWait",
	135: "received",
	136: "refresh",
	137: "refreshRow",
	138: "relative",
	139: "releaseConnection",
	140: "remove",
	141: "renderPage",
	142: "replace",
	143: "rowDeleted",
	144: "rowInserted",
	145: "rowUpdated",
	146: "run",
	147: "save",
	148: "saveOrUpdate",
	149: "send",
	150: "sendBase",
	151: "sendCommand",
	152: "sendKernelImpl",
	153: "sendMessage",
	154: "sendMessageAsync",
	155: "sendRequest",
	156: "send_request",
	157: "service",
	158: "set",
	159: "setFetchDirection",
	160: "setFetchSize",
	161: "start",
	162: "submitConsumeRequest",
	163: "syncInvoke",
	164: "systemErrorHandler",
	165: "touch",
	166: "update",
	167: "updateArray",
	168: "updateAsciiStream",
	169: "updateBigDecimal",
	170: "updateBinaryStream",
	171: "updateBlob",
	172: "updateBoolean",
	173: "updateByte",
	174: "updateBytes",
	175: "updateCharacterStream",
	176: "updateClob",
	177: "updateDate",
	178: "updateDouble",
	179: "updateFloat",
	180: "updateImpl",
	181: "updateInt",
	182: "updateLong",
	183: "updateNCharacterStream",
	184: "updateNClob",
	185: "updateNString",
	186: "updateNull",
	187: "updateObject",
	188: "updateRef",
	189: "updateRow",
	190: "updateRowId",
	191: "updateSQLXML",
	192: "updateShort",
	193: "updateString",
	194: "updateTime",
	195: "updateTimestamp",
	196: "versionedRead",
	197: "writeWithCommandProtocol",
	198: "write_args",
	199: "requestInitialized",
	200: "main",
	201: "postConstruct",
	202: "getMajorVersion",
	203: "installMBeanServer",
	204: "boot",
	205: "setContentType",
	206: "prepareResponse",
	207: "invokeSync",
	208: "performInvocation",
	209: "render",
	210: "exec",
	211: "acquireNextTrigger",
	212: "waitFor",
	213: "query",
	214: "ping",
	215: "deleteByQuery",
	216: "rollback",
	217: "optimize",
	218: "commit",
	219: "submit",
	220: "processAction",
	221: "findKey",
	222: "tpcall",
	223: "convertActionConfig",
}

type SQLEntity struct {
	Table   string
	Operate string
}

type SQLURLEntity struct {
	Host     string
	Port     string
	Database string
	Type     string
}
